<?php 
error_reporting(0);
require_once ('config.php');
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=0" />
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<title>我的项目</title>
<link href="global.css" rel="stylesheet" type="text/css" />
<style type="text/css">
.message-box{
width:88%;
margin-top:6%;
}
body{
padding-bottom:20px;
}
label{
display:block;
text-align:center;
font-size:14px;
padding:5px;
margin:auto;
width:60px;
}
hr{
margin:8px;
}
.title-img{
height:25px;
width:auto;
margin-bottom:-10px;
}
.ex-btn{
display:inline-block;
padding:8px;
}
.container{
display:block;
width:100%;
}
.message-box .btn{
float:none;
margin:auto;
margin-top:15px;
margin-bottom:10px;
}
a{
color:#fe6565;
display:inline-block;
position:static;
}
#wexin-login-btn{
margin-bottom:10px;
}
.message-box .content{
max-height:none;
margin-bottom:5px;
margin-top:5px;
}
.circle-icon{
width:18px;
height:18px;
border-radius:9px;
background-color:#F0BEE0;
}
.circle-icon span{
color:white;
}
.hint-box{
font-size:small;
}
input{
text-align:center;
}
p{
font-size:14px;
}
a{
font-size:14px;
}
#area-select{
cursor:pointer;
width: 186px;
text-align: center;
color: #444;
background-color: #fff;
background-size: auto 15px;
padding: 8px;
border-radius: 8px;
border: 1px solid #ddd;
}
</style>
<?php
//$sql="select * from d_pro_grame where d_user_id=4 order by d_user_id desc";
//$result=mysql_query($sql);
$sql1="select * from d_programe where d_pro_id='".$_GET['id']."'";
$rs1=mysql_fetch_array(mysql_query($sql1));
global $original;
$original=$rs1['d_pro_days'];

function cal($str,$momey_total,$money_n,$money_p)
{
  $find = '1';
  preg_match_all('/'.$find.'/', $str, $matches);
  global $n,$l,$money_n,$money_p;
  $n=count($matches[0]);
  $l=strlen($str);
  //echo $n."</br>";
  //echo $l."</br>";
  $money_n=round($n/$l*$momey_total);
  //echo $money_n."</br>";
  $money_p=$momey_total-$money_n."</br>";
  //echo $money_p."</br>";
}

function yes($num,$orl,$cycle)
{ 
  //echo $orl."</br>";
  $new=$orl."1";
  $l=strlen($new);
  if($l<=$cycle)
  {
    mysql_query($sql="update d_programe set d_pro_days=$new where d_pro_id=$num");
    echo "<script>alert('Insist,Days+1');location='my_supervise.php';</script>";
  }
  else
  {
     echo "<script>alert('Error,Programe is over!');location='my_supervise.php';</script>";
  }  
}

function no($num,$orl,$cycle)
{
  //echo $orl."</br>";
  $new=$orl."0";
  $l=strlen($new);
  if($l<=$cycle)
  {
    mysql_query($sql="update d_programe set d_pro_days=$new where d_pro_id=$num");
    echo "<script>alert('Abandon,Days+0');location='my_supervise.php';</script>";
  }
  else
  {
     echo "<script>alert('Error,Programe is over!');location='my_supervise.php';</script>";
  }  
}


if($_POST["submit1"])
{ 
  yes($_GET['id'],$rs1['d_pro_days'],$rs1['d_pro_cycle']);  
}
if($_POST["submit2"])
{
  no($_GET['id'],$rs1['d_pro_days'],$rs1['d_pro_cycle']);
}

cal($rs1['d_pro_days'],$rs1['d_pro_money'],0,0);

if($_POST["submit3"])
{
  $sql4="select * from d_user where d_user_id='".$rs1['d_friend_id']."'";
  $sql5="select * from d_user where d_user_id='".$rs1['d_user_id']."'";
  $rs4=mysql_fetch_array(mysql_query($sql4));
  $rs5=mysql_fetch_array(mysql_query($sql5));
  //echo $rs4['d_user_money']."</br>";
  //echo $rs5['d_user_money'];
  $money_n=$money_n+$rs5['d_user_money'];
  $money_p=$money_p+$rs4['d_user_money'];
  mysql_query($sql6="update d_user set d_user_money='$money_n' where d_user_id='".$rs1['d_user_id']."'");
  mysql_query($sql7="update d_user set d_user_money='$money_p' where d_user_id='".$rs1['d_friend_id']."'");
  mysql_query($sql8="delete from d_programe where d_pro_id='".$rs1['d_pro_id']."'");
  //mysql_query($sql8="delete from d_programe where d_pro_id='2'");
  echo "<script>alert('OK');location='member.php';</script>";  
}

?>
</head>
<html>
<body>

<div id="login-box" class="message-box" >
<header class="fruit-bg-header"></header>
<div class="content" >
	<section class="container" >
		<h3><b><?php echo $rs1['d_pro_name'];?></b></h3>
		<span style="font-size:10px">
			项目来自<span style="font-size:20px;color:#fe6565"><b> 
			<?php 
			$sql2="select * from d_programe where d_pro_name='".$rs1['d_pro_name']."'";
			$rs2=mysql_fetch_array(mysql_query($sql2));
      
      $sql3="select * from d_user where d_user_id='".$rs2['d_friend_id']."'";
      $rs3=mysql_fetch_array(mysql_query($sql3));
      echo $rs3['d_user_nick'];
      
			?> </b></span>的监督			
		</span>

		<label></br>持续时间</label>
		<input type="text" readonly="readonly" value="<?php echo $rs1['d_pro_start'].'~'.$rs1['d_pro_end'];?>">
		<label>保证金</label>
		<input style="color:#fe6565" type="text" id="name"  readonly="readonly" value="<?php echo '￥'.$rs1['d_pro_money'];?>">
		<label>坚持天数</label>
		<?php $days=strlen($rs1['d_pro_days']);?>
		<input type="text" readonly="readonly" value="<?php echo '已经坚持 '.$days.' 天了';?>"></br>




	
	<section class="container" >
</div>

<footer id="footer-bar" >
<div class="head-border" ></div>
<div class="btn-wrapper" >
<div class="btn-list" >
<li id="home-btn" data-id="home" ><a href='member.php'><img src="./img/home-icon.png" class="icon"/>个人中心</a></li>
<li id="home-btn" data-id="home" ><a href='my_friends.php'><img src="./img/order-icon.png" class="icon"/>我的好友</a></li>
<li id="home-btn" data-id="home" ><a href='my_programe.php'><img src="./img/order-icon.png" class="icon"/>我的项目</a></li>
<li id="home-btn" data-id="home" ><a href='my_supervise.php'><img src="./img/order-icon.png" class="icon"/>监督项目</a></li>

</div>
</div>
</footer>


</body>
</html>
